package com.shinechain.service.user.impl;

import com.shinechain.botModel.InviteCheckBot;
import com.shinechain.botModel.ShineChainBot;
import com.shinechain.botModel.ShineChainProjectBot;
import com.shinechain.botModel.WorkBot;
import com.shinechain.command.CommandsHandler;
import com.shinechain.command.KeyCommand;
import com.shinechain.service.user.Proxy;
import com.shinechain.utils.PatternChat;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.telegram.telegrambots.ApiContext;
import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.TelegramBotsApi;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.exceptions.TelegramApiException;
import org.telegram.telegrambots.generics.LongPollingBot;
import org.telegram.telegrambots.generics.WebhookBot;

public class ProjectBotImpl implements Proxy {
    private static String BOT_NAME = "ShinechainBot";
    private static String BOT_TOKEN = "634777415:AAFmTHfxYspSOudhzhsqmfajH37VoUla-IU" /* your bot's token here */;

    private static String PROXY_HOST = "127.0.0.1" /* proxy host */;
    private static Integer PROXY_PORT = 1080/* proxy port */;
    private static String PROXY_USER = "lsq" /* proxy user */;
    private static String PROXY_PASSWORD = "lsq" /* proxy password */;

    private static ShineChainProjectBot shineChainProjectBot;
    private static ShineChainBot shineChainBot;
    private static WorkBot workBot;

    private static PatternChat patternChat;

    @Override
    public void init() {
        try {
            patternChat = new PatternChat();

            ApiContextInitializer.init();

            // Create the TelegramBotsApi object to register your bots
            TelegramBotsApi botsApi = new TelegramBotsApi();

            // Set up Http proxy
            DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);

            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(
                    new AuthScope(PROXY_HOST, PROXY_PORT),
                    new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD));

            HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT);

            RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(true).build();
            //botOptions.setRequestConfig(requestConfig);
            //botOptions.setCredentialsProvider(credsProvider);


            // botOptions.setHttpProxy(httpHost);
            // shineChainBot = new ShineChainBot(botOptions);
           // shineChainProjectBot = new ShineChainProjectBot(botOptions);
           // InviteCheckBot inviteCheckBot = new InviteCheckBot(botOptions);
            workBot = new WorkBot(botOptions);

            botsApi.registerBot(workBot);
            // botsApi.registerBot(shineChainProjectBot);
            // botsApi.registerBot(new CommandsHandler("红包BOT"));
            //botsApi.registerBot((LongPollingBot) new InviteCheckBot(botOptions));

        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
        //	SpringApplication.run(Springboot2MybatisDemoApplication.class, args);
    }

    public static ShineChainProjectBot getShineChainProjectBot() {
        return shineChainProjectBot;
    }

    public static WorkBot getWorkBot() {
        return workBot;
    }
}



